import time

import numpy as np
import cv2


cap = cv2.VideoCapture(0)

while True:

    # 读取当前帧
    ret, frame = cap.read()

    # 转换为灰度图像
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # 显示结果窗口
    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

    # 完成所有工作后，释放捕获
    cap.release()
    cv2.destroyAllWindows()
